home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / pascal / pibasy47.zip / TIMEREC.ASM < prev   
Assembly Source File  |  1988-02-11  |  4KB  |  106 lines

  1. ;
  2. ;  Check if a character in input comm buffer
  3. ;
  4.          MOV   AX,[>Async_Buffer_Tail]
  5.          CMP   AX,[>Async_Buffer_Head]
  6.          JNE   Rec1
  7. ;
  8. ;  Buffer empty -- begin wait loop.
  9. ;
  10.          MOV   AX,[BP+<Secs]                 ;Get seconds to wait
  11.          MOV   CX,10                         ;Shift count = 2 ** 10 = 1024
  12.          SHL   AX,CL                         ;Seconds * 1024 = milleseconds
  13.          MOV   CX,AX                         ;Move to looping register
  14. ;
  15. ;  Delay for 1 ms.
  16. ;
  17. Delay:   PUSH  CX                            ;Save milleseconds to go
  18.          MOV   CX,[>Async_OneMSDelay]        ;Get delay loop value for 1 ms
  19. Delay1:  LOOP  Delay1                        ;Tight loop for 1 ms delay
  20. ;
  21. ;  Check if any character yet.
  22. ;
  23.          POP   CX                            ;Get back millesecond count
  24. ;
  25.          MOV   AX,[>Async_Buffer_Tail]
  26.          CMP   AX,[>Async_Buffer_Head]
  27.          JNE   Rec1
  28. ;
  29. ;  Buffer still empty -- decrement elapsed time
  30. ;
  31.          LOOP  Delay                         ;Decrement millesecond count and loop
  32. ;
  33. ;  Dropped through -- no character arrived in specified interval.
  34. ;  Return TimeOut as result.
  35. ;
  36.          MOV   BX,>TimeOut                   ;Pick up timeout value
  37.          LES   DI,[BP+<C]                    ;Get result character address
  38.     ES:  MOV   [DI],BX                       ;Store timeout value
  39.          JMP   Return                        ;Return to caller
  40. ;
  41. ;  Buffer not empty -- pick up next character.
  42. ;
  43. Rec1:    LES   DI,[>Async_Buffer_Ptr]        ;Pick up buffer address
  44.          ADD   DI,AX                         ;Add character offset
  45.      ES: MOV   BL,[DI]                       ;Get character from buffer
  46. ;
  47.          XOR   BH,BH                         ;Clear high-order bits
  48.          LES   DI,[BP+<C]                    ;Get result address
  49.      ES: MOV   [DI],BX                       ;Store character from buffer
  50. ;
  51.          INC   AX                            ;Increment tail pointer
  52.          CMP   AX,[>Async_Buffer_Size]       ;Past end of buffer?
  53.          JLE   Rec2                          ;No -- skip wrapping
  54.          XOR   AX,AX                         ;Yes -- point to start of buffer
  55. Rec2:    MOV   [>Async_Buffer_Tail],AX       ;Update tail pointer
  56.          MOV   AX,[>Async_Buffer_Used]       ;Pick up amount of buffer used
  57.          DEC   AX                            ;Update buffer use count
  58.          MOV   [>Async_Buffer_Used],AX       ;
  59. ;
  60. ; Check how empty the receive buffer is.
  61. ; We may have previously sent XOFF, or dropped RTS, to
  62. ; stop sender from sending.  If so, and the buffer is
  63. ; now empty enough, we should re-enable the sender.
  64. ;
  65.          TEST  BYTE [<Async_Sender_On],1     ;See if sender enabled
  66.          JNZ   Return                        ;Skip buffer tests if so
  67. ;
  68.          CMP   AX,[>Async_Buffer_Low]        ;Check if low enough
  69.          JG    Return                        ;Still too full, skip
  70. ;
  71. ; Buffer is reasonably empty, send XON to get things rolling again
  72. ; if XOFF previously sent.
  73. ;
  74.          TEST  BYTE [<Async_XOff_Sent],1     ;Check if Xoff sent
  75.          JZ    Rec3                          ;No -- skip.
  76. ;
  77.          MOV   AX,>XON                       ;Else push XON onto stack
  78.          PUSH  AX
  79.          CALL  FAR [>Async_Send_Addr]        ;Call output routine
  80. ;
  81.          MOV   BYTE [>Async_XOff_Sent],0     ;Clear Xoff flag
  82. ;
  83. ; If RTS dropped because buffer was too full, enable RTS.
  84. ;
  85. Rec3:    TEST    BYTE [<Async_Do_Cts],1      ;Check if CTS/RTS checking
  86.          JZ      Rec4                        ;No -- skip
  87. ;
  88.          MOV     DX,[>Async_Uart_MCR]        ;Get modem control register
  89.          IN      AL,DX
  90.          OR      AL,<Async_RTS               ;Enable RTS
  91.          OUT     DX,AL
  92. ;
  93. ; If DTR dropped because buffer was too full, enable DTR.
  94. ;
  95. Rec4:    TEST    BYTE [<Async_Do_Dsr],1      ;Check if DSR/DTR checking
  96.          JZ      Rec5                        ;No -- skip
  97. ;
  98.          MOV     DX,[>Async_Uart_MCR]        ;Get modem control register
  99.          IN      AL,DX
  100.          OR      AL,<Async_DTR               ;Enable DTR
  101.          OUT     DX,AL
  102. ;
  103. Rec5:    MOV     BYTE [>Async_Sender_On],1   ;Indicate sender enabled
  104.  
  105. Return:  AND     Byte [>Async_Line_Status],$FD ;Remove overflow flag
  106.